/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gameheartv2;

import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author GaoXteen
 */
public class Card  extends JButton{

    int number;
    int type;
    int layer;
    String path;
    boolean isUse = false;
    public Card (int num, int _type)
    {
        number = num;
       type = _type;
       path =  System.getProperty("user.dir")+"\\src\\Resources\\" + Integer.toString(number+2)+"_"
               + Integer.toString(_type)+".gif";
       ImageIcon bgCard = new ImageIcon(path);
        super.init(null, bgCard);       
       
    }

     public Card (int num, int _type,int _layer)
    {
         layer = _layer;
        number = num;
       type = _type;
       path =  System.getProperty("user.dir")+"\\src\\Resources\\" + Integer.toString(number+2)+"_"
               + Integer.toString(_type)+".gif";
       ImageIcon bgCard = new ImageIcon(path);
        super.init(null, bgCard);

    }

    public void set(Card card)
    {
        this.number = card.number;
        this.path = card.path;
        this.layer = card.layer;
    }

    public String GetSourcePath()
    {
        return this.path;
    }

    public boolean isLower(Card card)
    {
        if(this.type <card.type)
            return true;
        if(this.type ==card.type)
        {
            if(this.number<card.number)
            {
                return true;
            }
        }
        return false;
    }

    public static void SapTangDan( Vector<Card> vCard)
    {
        for(int i = 0; i<vCard.size()-1;i++)
        {
            for(int j = i; j<vCard.size(); j++)
            {
                if(vCard.elementAt(j).isLower(vCard.elementAt(i)))
                {
                    int numj = vCard.elementAt(j).number;
                    int layerj = vCard.elementAt(j).layer;
                    int typej= vCard.elementAt(j).type;
                    Card tem = new Card(numj,typej,layerj);
                    tem.set(vCard.elementAt(j));
                    vCard.elementAt(j).set(vCard.elementAt(i));
                    vCard.elementAt(i).set(tem);
                }
            }
        }
    }
}
